From 9d3fb195af40f26a3751c368af55677667af3eba Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 23 May 2024 21:59:38 +0200 Subject: [PATCH] Fix argument name highlighting in 'describe-function' output This fixes a regression introduced in dd38097f0b9458eea882043fa06b27248e505b22, which prevented proper argument name highlighting in function docstrings in the output buffer of 'describe-function'. * lisp/help-fns.el (help-do-arg-highlight): New optional arg that says if we're highlighting arguments in the usage string or in the docstring. Tweak generated regex to only expect argument name to be preceded by function name in usage string. (help-highlight-arguments): Use new argument for usage string. --- lisp/help-fns.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 182b22549b5..a202c2d247e 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -362,14 +362,17 @@ if the variable `help-downcase-arguments' is non-nil." (propertize (if help-downcase-arguments (downcase arg) arg) 'face 'help-argument-name)) -(defun help-do-arg-highlight (doc args) +(defun help-do-arg-highlight (doc args &optional usage-p) (with-syntax-table (make-syntax-table emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\- "w") (dolist (arg args) (setq doc (replace-regexp-in-string ;; This is heuristic, but covers all common cases ;; except ARG1-ARG2 - (concat "([^ ]+ .*" ; skip function name + (concat (when usage-p + ;; Skip function name in usage string + ;; (Bug#65580). + "([^ ]+ .*") "\\<" ; beginning of word "\\(?:[a-z-]*-\\)?" ; for xxx-ARG "\\(" @@ -404,7 +407,7 @@ if the variable `help-downcase-arguments' is non-nil." (search-backward "(") (goto-char (scan-sexps (point) 1))))) ;; Highlight arguments in the USAGE string - (setq usage (help-do-arg-highlight (buffer-string) args)) + (setq usage (help-do-arg-highlight (buffer-string) args t)) ;; Highlight arguments in the DOC string (setq doc (and doc (help-do-arg-highlight doc args)))))) ;; Return value is like the one from help-split-fundoc, but highlighted -- 2.30.2